package top.ranzhang.controller.admin;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.entity.Enrollments;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IEnrollmentsService;

import java.util.List;

/**
 * 学生报名模块
 */
@RestController
@RequestMapping("/admin/enrollments")
public class EnrollmentsController {

    @Autowired
    private IEnrollmentsService enrollmentsService;

    /**
     * 创建学生报名信息
     *
     * @param enrollment
     */
    @PostMapping
    public Result create(@RequestBody Enrollments enrollment) {
        enrollmentsService.save(enrollment);
        return Result.success();
    }

    /**
     * 获取所有学生报名信息
     *
     * @return
     */
    @GetMapping
    public Result getAll() {
        return Result.success(enrollmentsService.getAll());
    }

    /**
     * 根据id获取学生报名信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(enrollmentsService.getById(id));
    }

    /**
     * 更新学生报名信息
     *
     * @param enrollment
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody Enrollments enrollment) {
        enrollment.setEnrollmentId(id);
        enrollmentsService.update(enrollment);
        return Result.success();
    }

    /**
     * 删除学生报名信息
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        enrollmentsService.delete(id);
        return Result.success();
    }

}
